package com.asiainfo.dacp.datastash.broker.util;

import java.util.concurrent.Callable;

import com.asiainfo.dacp.datastash.common.WorkerExecutor;
/**
 * @author Wugf
 * @date 2016-03-08
 */
public class ThreadEntity implements Callable<CallableResult> {

	private WorkerExecutor entry;
	public int FAILURE = 1;
	public static final String SUCCESS_MSG = "success";
	public static final int SUCCESS = 0;
	private String[] args;
	public ThreadEntity(WorkerExecutor entry,String[] args) {
		this.entry = entry;
		this.args=args;
	}

	public CallableResult call() throws Exception {
		CallableResult result=null;

		try {
			int rtnCode=entry.execute(args);
			if(rtnCode==0)
				result= new CallableResult(SUCCESS, SUCCESS_MSG,entry);
			else
				result= new CallableResult(FAILURE, "返回值不为0，程序执行失败",entry);


		} catch (Exception e) {			
			e.printStackTrace();
			result=new CallableResult(FAILURE, e.getMessage(),entry);
		}
		return result;
	}

	

}
